package com.mio.web.common;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.fileupload.ProgressListener;


public class ResourceProgressListener  implements ProgressListener{
    private HttpSession session;
    
    public ResourceProgressListener(HttpServletRequest request) {
       session = request.getSession();
       ProcessInfo newUploadStatus = new ProcessInfo();
       session.setAttribute("currentUploadStatus", newUploadStatus);
    }
 
    public void update(long readedBytes, long totalBytes, int currentItem) {
    	ProcessInfo pri = (ProcessInfo) session.getAttribute("currentUploadStatus"); 
        pri.itemNum = currentItem;  
        pri.readSize = readedBytes;  
        pri.totalSize = totalBytes;  
        pri.show = readedBytes/1024/8+"/"+totalBytes/1024/8+"KB";  
        pri.rate = Math.round(new Float(readedBytes) / new Float(totalBytes)*100);  
    }
}
